import request from "@/utils/request";
import { AxiosPromise } from "axios";
import {
  ItemPageResult,
  ItemPageResult2,
  ItemPageVO2,
  ItemForm,
} from "./types";

/**
 * 试卷管理
 *
 * @param queryParams
 */
export function getTestPaperList(
  queryParams?: ItemForm
): AxiosPromise<ItemPageResult> {
  return request({
    url: "/adminApi/paper/page",
    method: "get",
    params: queryParams,
  });
}

/**
 * 新增试卷
 *
 * @param data
 */
export function paperCreate(data: ItemForm) {
  return request({
    url: "/adminApi/paper/create",
    method: "post",
    data: data,
  });
}

/**
 * 修改试卷
 *
 * @param data
 */
export function paperUpdate(data: ItemForm) {
  return request({
    url: "/adminApi/paper/update",
    method: "put",
    data: data,
  });
}

/**
 * 删除试卷
 *
 * @param id
 */
export function paperDelete(id: any) {
  return request({
    url: "/adminApi/paper/delete?id=" + id,
    method: "delete",
  });
}

/**
 * 试题列表
 *
 * @param queryParams
 */
export function getTestQuestionsList(
  queryParams?: ItemForm
): AxiosPromise<ItemPageResult2> {
  return request({
    url: "/adminApi/question/page",
    method: "get",
    params: queryParams,
  });
}

/**
 * 新增试题
 *
 * @param data
 */
export function questionCreate(data: any) {
  return request({
    url: "/adminApi/question/create",
    method: "post",
    data: data,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}

/**
 * 修改试题
 *
 * @param data
 */
export function questionUpdate(data: any) {
  return request({
    url: "/adminApi/question/update",
    method: "put",
    data: data,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}

/**
 * 删除试题
 *
 * @param id
 */
export function questionDelete(id: number) {
  return request({
    url: "/adminApi/question/delete?id=" + id,
    method: "delete",
  });
}

/**
 * 下载模版
 *
 */
export function downloadTemplate() {
  return request({
    url: "/adminApi/question/download",
    method: "get",
    responseType: "arraybuffer",
  });
}

/**
 * 导入题目
 *
 * @param data
 */
export function questionUpload(data: any) {
  return request({
    url: "/adminApi/question/upload",
    method: "post",
    data: data,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}
